Step 11: PUT Request
Let's include a route to update a bookmark.
| HTTP Method | PUT |
|---|---|
| API Endpoint | /bookmarks/:id |
| Request Path Parameter | id |
| Request Query Parameter | |
| Request Body | JSON object (bookmark attributes) |
| Response Body | JSON object (updated bookmark) |
| Response Status | 200 |
Update src/routes/bookmarks.js:
router.put("/bookmarks/:id", (req, res) => {
const { id } = req.params;
const { title, url } = req.body;
const bookmarks = bookmarkDao.update({ id, title, url });
res.json({
status: 200,
message: `Successfully updated the following bookmark!`,
data: bookmarks,
});
});
Save the code and commit the changes. Then, test this endpoint in Postman.
